Many applications and libraries are distributed in an intermediate format, such as MICROSOFT® Intermediate Language (MSIL). These intermediate language binaries (also known as managed assemblies in the case of MICROSOFT®.NET) are typically compiled dynamically at runtime in a virtual machine environment using a Just-in-Time (JIT) compiler. An alternative to dynamic compilation is pre-compilation via Native Generation (NGen). NGen generates machine code and runtime data structures from the intermediate language and persists them in files on disk. The images produced by NGen are called Native or NGen images. Unlike JIT-compiled code, code and data structures in NGen images can be shared across processes. For libraries and frameworks that are typically shared across multiple processes, NGen is extremely useful since it minimizes the working set of each managed process. NGen therefore reduces the overall memory utilization of the system. NGen is also very useful for minimizing start up time of client-side applications.
Several managed platforms/applications are using NGen. Unfortunately, however, it is quite difficult to use NGen in these current platforms. Since NGen images need to be created on the end-user machine, NGen commands need to be chained through the framework/application's installer. Typically, that involves writing a custom action (such as a MIROSOFT® WINDOWS® Installer action) that invokes a command-line tool (ngen.exe in the case of MICROSOFT® .NET).Custom actions are not trivial to write. Moreover, NGen images may become invalidated for a variety of reasons (such as when the corresponding libraries/assemblies are serviced), and need to be regenerated each time that happens by issuing explicit commands through the command line tool.